package  control.controlBoxParts
{
	import com.danoo.components.ControlPoint;
	import com.danoo.constants.PosConst;
	
	import mx.core.EdgeMetrics;
	import mx.skins.halo.HaloBorder;
	
	public class ControlSkin extends  HaloBorder
	{
		
		public function ControlSkin()
		{
			super();
		}

		
		public override  function get borderMetrics():EdgeMetrics
        {   
	        var recWidth: int =  getStyle("controlRecWidth");
	         if(!_borderMetrics)
	         {
	         	_borderMetrics = new EdgeMetrics(0, 0, 0, 0);
	         	var bt:Number = getStyle("borderThickness");
		        var btl:Number = getStyle("borderThicknessLeft");
		        var btt:Number = getStyle("borderThicknessTop");
		        var btr:Number = getStyle("borderThicknessRight");
		        var btb:Number = getStyle("borderThicknessBottom");
		        _borderMetrics.left = recWidth ;
		        _borderMetrics.top = recWidth ;
		        _borderMetrics.right = recWidth; 	       
		        _borderMetrics.bottom = recWidth ; 
	         } 
	        return _borderMetrics;
  	   }

		/**
		 *  @private
		 *  If borderStyle may have changed, clear the cached border metrics.
		 */
		public override  function styleChanged(styleProp:String):void
		{
			super.styleChanged(styleProp);
			
			if (styleProp == null ||
				styleProp == "styleName" ||
				styleProp == "borderStyle" ||
				styleProp == "borderThickness" ||
				styleProp == "borderThicknessTop" ||
				styleProp == "borderThicknessBottom" ||
				styleProp == "borderThicknessLeft" ||
				styleProp == "borderThicknessRight" ||
				styleProp == "borderSides" )
			{
				_borderMetrics = null;
			}
			
			invalidateDisplayList();
		}
		
		protected override function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
		{
			var recWidth: int =  getStyle("controlRecWidth");
			var half: int = recWidth / 2;
			this.move(half, half);
			var width: Number = unscaledWidth - 1 * recWidth;
			var height: Number = unscaledHeight - 1 * recWidth;
			var halfWidth:Number = width / 2;
			var halfHeight: Number = height / 2;
			/* this.x = halfWidth;
			this.y = halfWidth;
			this.width = unscaledWidth - recWidth;
			this.height = unscaledHeight - recWidth; */
			graphics.clear();
			
			if(!this.parent || !this.parent["showControl"])
			{
				return;
			}
			var focusColor:Number = getStyle("themeColor");
			graphics.lineStyle(1, focusColor);

			//先再画矩形：
			
			//左上
			//graphics.drawRect(- half, - half, recWidth, recWidth);

			
			//中上
			//graphics.drawRect(halfWidth - half, - half, recWidth, recWidth);

			
			//右上
			//graphics.drawRect(width - half, - half, recWidth, recWidth);
		
			
			//左中
//			graphics.drawRect(- half, halfHeight - half, recWidth, recWidth);
          
			
			//右中
//			graphics.drawRect(width - half, halfHeight - half, recWidth, recWidth);
		
			
			//左下
//			graphics.drawRect(- half, height - half, recWidth, recWidth);
			
			//中下
//			graphics.drawRect(halfWidth - half, height - half, recWidth, recWidth);
			
			
			//右下
//			graphics.drawRect(width - half, height - half, recWidth, recWidth);

           
			
			//再画线作为边框：
			
			//上左
		   /*  graphics.moveTo(half, 0);
		    graphics.lineTo(halfWidth - half, 0);
		    
			//上右
		    graphics.moveTo(halfWidth + half, 0);
		    graphics.lineTo(width - half, 0);
		    
		    //左上
		    graphics.moveTo(0, half);
		    graphics.lineTo(0, halfHeight - half);
		    
		    //左下
		    graphics.moveTo(0, halfHeight + half);
		    graphics.lineTo(0, height - half);
		    
		    
		    //右上
		    graphics.moveTo(width , half);
		    graphics.lineTo(width, halfHeight - half);
		    
		    //右下
		    graphics.moveTo(width , halfHeight + half);
		    graphics.lineTo(width, height - half);
		    
		    
		    //下左
		    graphics.moveTo(half, height);
		    graphics.lineTo(halfWidth - half, height);
		    
		    
		    //下右
		    graphics.moveTo(halfWidth + half, height);
		    graphics.lineTo(width - half, height); */
			
		}
	}
}